using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using JGSY.CMS.LowCode.Platform.Infrastructure.ServiceCollectionExtensions;
using JGSY.CMS.LowCode.Platform.Infrastructure.Services;
using JGSY.CMS.LowCode.Platform.Application.Interfaces;
using JGSY.CMS.LowCode.Platform.Application.Services;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules.Modules
{
    /// <summary>
    /// 应用业务服务模块
    /// 包含所有业务逻辑服务的注册
    /// </summary>
    public class ApplicationServicesModule : IServiceModule
    {
        public string ModuleName => "应用业务服务";
        public int Priority => 7;
        public bool LoadInFastMode => false; // 快速模式下延迟加载
        public ModulePermission RequiredPermission => ModulePermission.ApplicationServices;
        public bool IsCriticalModule => false; // 非关键模块

        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            // 完整应用服务功能
            ConfigureAllApplicationServices(services);
        }

        public void ConfigureMinimalServices(IServiceCollection services, IConfiguration configuration)
        {
            // 精简应用服务功能 - 只注册核心应用服务
            services.AddCoreApplicationServices();
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 应用服务模块无特殊配置要求
            return true;
        }

        private void ConfigureAllApplicationServices(IServiceCollection services)
        {
            // 注册核心应用服务
            services.AddCoreApplicationServices();
            
            // 注册应用服务接口和实现
            services.AddApplicationServices();
            
            // 多租户服务
            services.AddScoped<ITenantContext, TenantContext>();
            services.AddScoped<ITenantService, TenantService>();
            services.AddScoped<ITenantResourceQuotaService, TenantResourceQuotaService>();
            services.AddScoped<ITenantMonitoringService, TenantMonitoringService>();
            services.AddScoped<ITenantDataManagementService, TenantDataManagementService>();
            
            // 通知系统
            services.AddScoped<INotificationService, NotificationService>();
            
            // 审计系统
            services.AddScoped<IAuditService, AuditService>();
            
            // 监控服务
            services.AddScoped<JGSY.CMS.LowCode.Platform.Application.Interfaces.Monitoring.IMonitoringService, 
                               JGSY.CMS.LowCode.Platform.Application.Services.Monitoring.MonitoringService>();
        }
    }
}
